<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" />
        <title>resource timing information for cross-origin resource request with timing-allow-origin</title>
        <link rel="author" title="Intel" href="http://www.intel.com/" />
        <link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="/webperf/tests/resources/webperftestharness.js"></script>
        <script>
            
            setup({explicit_done: true});
            test_namespace();
            var pageOrigin = "w3c-test.org";
            var crossOrigin = "www.w3c-test.org";

            function onload_test()
            {
                if (!performance || !performance.getEntriesByName)
                {
                    test_true(false, "Performance Timeline interface required by this test is supported!");
                    done();
                    return;                    
                }

                var entry = performance.getEntriesByName(document.getElementById("frameContext").src, "resource")[0];

                test_equals(entry.redirectStart, 0, "redirectStart should be 0 in cross-origin request since no redirect!");
                test_equals(entry.redirectEnd, 0, "redirectEnd should be 0 in cross-origin request since no redirect!");
                test_greater_than(entry.domainLookupStart, 0, "domainLookupStart should not be 0 in timing-allow cross-origin request!");
                test_greater_than(entry.domainLookupEnd, 0, "domainLookupEnd should not be 0 in timing-allow cross-origin request!");
                test_greater_than(entry.connectStart, 0, "connectStart should not be 0 in timing-allow cross-origin request!");
                test_greater_than(entry.connectEnd, 0, "connectEnd should not be 0 in timing-allow cross-origin request!");
                test_greater_than(entry.requestStart, 0, "requestStart should not be 0 in timing-allow cross-origin request!");
                test_greater_than(entry.responseStart, 0, "responseStart should not be 0 in timing-allow cross-origin request!");
                if (entry.secureConnectionStart)
                    test_equals(entry.secureConnectionStart, 0, "secureConnectionStart should be 0 in cross-origin request since no ssl!");
                test_greater_than(entry.fetchStart, 0, "fetchStart should not be 0 in timing-allow cross-origin request!");
                test_greater_than(entry.responseEnd, 0, "responseEnd should not be 0 in timing-allow cross-origin request!");
                done();
            }

        </script>

    </head>
    <body>
        <h1>Description</h1>
        <p>This test validates the values in resource timing for a timing-allow-origin cross-origin resource request.</p>

        <br />
        <iframe id="frameContext" src="" style="width: 250px; height: 250px;"></iframe>
        <script>
            test_equals(document.location.host, pageOrigin, 'Starting document.location.hostname is correct (' + pageOrigin + ')');

            var requestUrl = 'http://' + crossOrigin + '/webperf/tests/resources/blank_page_green_with_allow_timing.php';
            requestUrl += '?origin=http://' + pageOrigin;

            var frameContext = document.getElementById("frameContext");
            frameContext.onload = onload_test;
            frameContext.src = requestUrl;
        </script>
        <div id="log"></div>
    </body>
</html>
